package yt.kpool.adapter;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.king.base.adapter.ViewHolderRecyclerAdapter;
import com.king.base.adapter.holder.ViewHolder;

import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.List;

import yt.kpool.R;
import yt.kpool.activity.profit.ProfitDetailAc;
import yt.kpool.bean.BtcProfitBean;
import yt.kpool.bean.ProfitBean;

/**
 * btc收益
 */
public class ProfitBtcAdapter extends ViewHolderRecyclerAdapter<BtcProfitBean.DataBean.ProfitListBean> {
    private Context contexts;
    private String DW;
    public ProfitBtcAdapter(Activity context, List<BtcProfitBean.DataBean.ProfitListBean> listData) {
        super(context, listData);
        contexts = context;

    }

    @Override
    public View buildConvertView(LayoutInflater layoutInflater, int viewType) {
        return layoutInflater.inflate(R.layout.item_btc_profit, null);
    }

    @Override
    public void bindViewDatas(ViewHolder holder, final BtcProfitBean.DataBean.ProfitListBean dataBean, int position) {

        holder.setText(R.id.tv_time, dataBean.getProfitTime());
        holder.setText(R.id.tv_profittype, dataBean.getProfitType());
        DecimalFormat df = new DecimalFormat("#####0.00000000");
        RelativeLayout rl_fpps = holder.getView(R.id.rl_fpps);
        if ("FPPS".equals(dataBean.getProfitType()))
        {
            rl_fpps.setVisibility(View.VISIBLE);
            holder.setText(R.id.tv_profitamount,df.format(dataBean.getPPSAmountForFPPS()+dataBean.getFPPSAmount()) );//收益
            holder.setText(R.id.tv_ppsamount,"PPS 结算 "+df.format(dataBean.getPPSAmountForFPPS())+" BTC");
            holder.setText(R.id.tv_fppsreturn,"FPPS 返利 "+df.format(dataBean.getFPPSAmount())+" BTC");
            holder.setText(R.id.tv_profittype2,"PPS");//可能获得收益
            holder.setText(R.id.tv_may_profit,df.format(dataBean.getPPSAmountForPPS()));

        }else {
            rl_fpps.setVisibility(View.GONE);
            holder.setText(R.id.tv_profitamount,df.format(dataBean.getPPSAmountForPPS()) );//收益
            holder.setText(R.id.tv_profittype2,"FPPS");//可能获得收益
            holder.setText(R.id.tv_may_profit,df.format(dataBean.getPPSAmountForFPPS()));
        }
        holder.setText(R.id.tv_hashrate,dataBean.getHashrate());//平均算例

        NumberFormat format=NumberFormat.getNumberInstance();
        format.setMaximumFractionDigits(2);
        DecimalFormat dfs = new DecimalFormat("#####0.00");
        holder.setText(R.id.tv_ratio,dfs.format(dataBean.getRatio()*100)+"%");//分层比例
        holder.setText(R.id.tv_fppsprofit,dataBean.getFPPSProfit());//fpps理论收益
        holder.setText(R.id.tv_ppsprofit,dataBean.getPPSProfit());//pps理论收益


        final ProfitBean.DataBean dataBeans=new ProfitBean.DataBean();
        dataBeans.setAddressUrl(dataBean.getAddressUrl());
        dataBeans.setAddress(dataBean.getAddress());
        dataBeans.setHashUrl(dataBean.getHashUrl());
        dataBeans.setHash(dataBean.getHash());
        dataBeans.setProfitTime(dataBean.getProfitTime());
        dataBeans.setHashrate24H(dataBean.getHashrate());
        if ("FPPS".equals(dataBean.getProfitType())){
                    dataBeans.setAmount(dataBean.getPPSAmountForFPPS()+dataBean.getFPPSAmount());
        }else {
            dataBeans.setAmount(dataBean.getPPSAmountForPPS());
        }
        holder.getConvertView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ProfitDetailAc.start(context,dataBeans,DW);
            }
        });
    }


  public void setDw(String DWS)
  {
      DW=DWS;
  }
}
